package com.netty;

import com.netty.dto.Message;
import io.netty.channel.ChannelFutureListener;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;

/**
 * @author CHL
 * @ClassName: SenderMessageHandler
 * @Description: 消息发送端消息发送
 * @date 2022/12/30 16:26
 * @Version 1.0
 */
public class SenderMessageHandler extends ChannelInboundHandlerAdapter {

    private final Message message;

    public SenderMessageHandler(Message message) {
        this.message = message;
    }

    @Override
    public void channelActive(ChannelHandlerContext ctx) throws Exception {
        System.out.println("sender发送消息：" + message);
        ctx.channel().writeAndFlush(message).addListener(ChannelFutureListener.CLOSE);

    }
}
